#include "FeaturePool.h"

FeaturePool::FeaturePool() {}

FeaturePool::~FeaturePool() {}

void FeaturePool::ComputeAppDescriptor(IplImage *img1, IplImage *img2)
{
	this->elem.clear();
	Hist* h1 = new Hist(cvGetSize(img1));
	Hist* h2 = new Hist(cvGetSize(img2));
	Utils *utils = new Utils();

	vector<float> mat1 = h1->computeHist(img1, cvRect(0,0,img1->width/2,img1->height/2));
	vector<float> mat2 = h2->computeHist(img2, cvRect(0,0,img2->width/2,img2->height/2));
	float r = utils->ComputeDistance(mat1, mat2);
	this->elem.push_back(r);

	mat1 = h1->computeHist(img1, cvRect(img1->width/2, 0, img1->width/2, img1->height/2));
	mat2 = h2->computeHist(img2, cvRect(img2->width/2, 0, img2->width/2, img2->height/2));
	r = utils->ComputeDistance(mat1, mat2);
	this->elem.push_back(r);

	mat1 = h1->computeHist(img1, cvRect(0, img1->height/2, img1->width/2, img1->height/2));
	mat2 = h2->computeHist(img2, cvRect(0, img2->height/2, img2->width/2, img2->height/2));
	r = utils->ComputeDistance(mat1, mat2);
	this->elem.push_back(r);

	mat1 = h1->computeHist(img1, cvRect(img1->width/2, img1->height/2, img1->width/2, img1->height/2));
	mat2 = h2->computeHist(img2, cvRect(img2->width/2, img2->height/2, img2->width/2, img2->height/2));
	r = utils->ComputeDistance(mat1, mat2);
	this->elem.push_back(r);	

	/* compute HOG features */
	HOG hog;
	// half above	
	float d = hog.ComputeHOGDistanceImg(img1,cvRect(0,0,img1->width,img1->height/2),
		img2,cvRect(0,0,img2->width,img2->height/2),8);
	this->elem.push_back(d);

	// half below	
	d = hog.ComputeHOGDistanceImg(img1,cvRect(0,img1->height/2,img1->width,img1->height),
		img2,cvRect(0,img2->height/2,img2->width,img2->height),8);
	this->elem.push_back(d);

	// half left
	d = hog.ComputeHOGDistanceImg(img1,cvRect(0,0,img1->width/2,img1->height),
		img2,cvRect(0,0,img2->width/2,img2->height),8);
	this->elem.push_back(d);

	// half right	
	d = hog.ComputeHOGDistanceImg(img1,cvRect(img1->width/2,0,img1->width,img1->height),
		img2,cvRect(img2->width/2,0,img2->width,img2->height),8);
	this->elem.push_back(d);

	/* compute covariance matrix */
	//CovarianceMatrix cm;
	//CvMat c2 = cm.computeCovarianceMatrix(img2);
	//CvMat c1 = cm.computeCovarianceMatrix(img1);
	//CvMat* eigenValues = cm.computeEigenValues(c1,c2);

	//for (int i = 0; i < eigenValues->rows; i++)
	//{
	//	this->elem.push_back(cvGetReal2D(eigenValues,i,0));
	//}

	this->featurePool.push_back(elem);
}